package com.showcai.tools;

import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.util.SHA256Tools;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Baggio on 2018-9-14.
 */
public class PushTools extends  ToolsBase  {
    /**
     * 调用手表厂家接口
     */
    private static final String CHANNEL_ID ="10016";
    private static final String CHANNEL_SECRET ="Sh85ZTJkzQyt1hrq1lEtjIfAaR7DNzS";

    /*push内容到手表*/
    public static void push2DevicService(String devicId,String body){

        String devicUrl="https://api.weixiaobao.com/umeox/channelApi/devices/push/"+devicId;
       // app.key=abcdefrt
      //  String devicUrl= PropertyUtils.getValue("devic.url")+devicId;
        logger.info(devicUrl);
        logger.info(body);

        Map<String,String> headMap=new HashMap<>();
        headMap.put("Accept","application/json");
        String timestamp =String.valueOf(System.currentTimeMillis());
        headMap.put("channel_id",CHANNEL_ID);
        headMap.put("timestamp",timestamp);
        String sign=CHANNEL_ID + CHANNEL_SECRET + timestamp;
        headMap.put("sign", SHA256Tools.getSHA256Str(sign));
        headMap.put("Content-Type","application/json;charset=utf-8");
        try {
            String resStr= HttpClientHelper.postJson(devicUrl,body.trim(),headMap);
            System.out.println(resStr);
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyRunTimeExcption(e.getMessage());
        }
    }

    public static void main(String[] args) {
        System.out.println(new Date());
        String devicId="863961040031337";
        String body = "{\"type\":3,\"devicId\":\"" + devicId + "\"}";
        System.out.println(body);
        PushTools.push2DevicService(devicId, body);
    }

}
